package br.indt.framework.ui.common;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import br.indt.framework.log.MicrologWrapper;
import br.indt.framework.ui.ImageLoader;

public abstract class PopUpItem extends Widget {
	
	private static final MicrologWrapper log = MicrologWrapper.getLogger(PopUpItem.class);
	
	protected static final int ARC_W = 18;
	protected static final int ARC_H = 18;
	protected static final int ICON_W = 45;
	protected static final int ICON_H = 45;
	protected static final int MOVING = 29;

	protected static final int POS_ICON_ERRO = ICON_W*2;
	protected static final int POS_ICON_ALERT = ICON_W*1;
	protected static final int POS_ICON_SUCCESS = ICON_W*0;

	protected static int ICON_X;
	protected static final int ICON_Y = 142+27;

	protected static final int HEIGHT_ITEM = 190;//178; //129
	protected Image icons = null;
	protected int type = PopUpScreen.ALERT;
//	protected String noteTitle;
	protected String note;

	protected Label lbTitle = null;
	protected Label lbNote = null;

	public PopUpItem() {
		super("popitem");

		lbTitle = new Label("lbTitle", null, false, 1, null);
		lbNote = new Label("lbNote", "", true, 3, null);

//		lbTitle.setMargin(0, 0, 20, 0);
//		lbNote.setMargin(17, 0, 20, 0);
		lbTitle.setAlign(Graphics.HCENTER);

		lbTitle.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		lbNote.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		lbNote.setAlign(Graphics.HCENTER);

		try {
			icons = ImageLoader.load("/icon/note_icons.png");
			ICON_X = (Display.getInstance().getWidth()/2)-(ICON_W/2);
		} catch (Exception e2) {
			//#ifdef LOGS
			log.error("[ERROR] " + this.getClass().getName() + "::PopUpItem() : " + e2.getMessage());
			//#endif
		}

		calculateHeight();
	}

	public void setWidth(int width) {
		this.width = width;
		lbTitle.setWidth(width);
		lbNote.setWidth(width);
		calculateHeight();
	}

	private void calculateHeight() {
		height = HEIGHT_ITEM;
	}

	public int getHeight() {
		return height;
	}

	public abstract void paint(Graphics g, int x, int y, int maxWidth, int maxHeight);

	public void click(int x, int y) {
	}

	public void pressFire() {
		click(0, 0);
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
		lbNote.setText(note);
	}
}